//
//  HMShoppingCartImageView.m
//  HowToDo
//
//  Created by Stan on 2017-01-07.
//  Copyright © 2017 KY. All rights reserved.
//

#import "HMShoppingCartImageView.h"

@interface HMShoppingCartImageView ()
@property(strong,nonatomic)UILabel *numberLabel;


@end

@implementation HMShoppingCartImageView

+ (instancetype)shoppingCartImageView {
    
    HMShoppingCartImageView *imageView = [[HMShoppingCartImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"new_navbar_chat_blod"];

    
    imageView.contentMode = UIViewContentModeRight;
    
    
    UILabel *numberLabel = [[UILabel alloc]init];
    imageView.numberLabel = numberLabel;
    
    numberLabel.backgroundColor = [UIColor redColor];
    numberLabel.textColor = [UIColor whiteColor];
    numberLabel.font = [UIFont systemFontOfSize:9.0];
    numberLabel.textAlignment = NSTextAlignmentCenter;
    numberLabel.text = [NSString stringWithFormat:@"%02zd",imageView.badge];
    //    numberLabel.text = [NSString stringWithFormat:@"66"];
    
    imageView.numberLabel = numberLabel;
    
    [imageView addSubview:imageView.numberLabel];
    [imageView.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.right.offset(0);
    }];
    
    [imageView.numberLabel layoutIfNeeded];
    imageView.numberLabel.layer.cornerRadius = imageView.numberLabel.bounds.size.height * 0.5;
    imageView.numberLabel.layer.masksToBounds = YES;
    return imageView;
}



- (void)setBadge:(NSInteger)badge{
    _badge = badge;
    
    self.numberLabel.text = [NSString stringWithFormat:@"%02zd",_badge];
    
}

@end
